/**
 * 受歧视的unions
 * */
// interface Shape {
//   kind: 'circle' | 'square',
//   radius?: number,
//   sideLength?: number
// }

// 第一个类型
interface Circle {
  kind: 'circle',
  radius: number,
}

// 第二个类型
interface Square {
  kind: 'square',
  sideLength: number
}

type Shape = Circle | Square
// function handleShape(shape: Shape) {
//   if (shape.kind === 'rect') { }
// }

function getArea(shape: Shape) {
  switch (shape.kind) {
    case 'circle':
      return Math.PI * shape.radius ** 2;
    case 'square':
      return shape.sideLength ** 2;
    default:
      break;
  }
}